package com.wc.AlgoOJ_train.train2_DP训练.c2.DPE006;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/12 17:10
 * @description 最长公共子序列
 * http://43.138.190.70:8888/p/DPE006
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int[] posX = new int[]{-1, 0, -1};
    static int[] posY = new int[]{-1, -1, 0};

    public static void main(String[] args) {
        String s1 = " " + sc.next();
        String s2 = " " + sc.next();
        char[] ch1 = s1.toCharArray();
        char[] ch2 = s2.toCharArray();

        int n = s1.length() - 1;
        int m = s2.length() - 1;
        int[][] dp = new int[n + 1][m + 1];
        int[][] pos = new int[n + 1][m + 1];

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (ch1[i] == ch2[j]) {
                    pos[i][j] = 0;
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    if (dp[i - 1][j] >= dp[i][j - 1]) {
                        dp[i][j] = dp[i - 1][j];
                        pos[i][j] = 2;
                    } else {
                        dp[i][j] = dp[i][j - 1];
                        pos[i][j] = 1;
                    }
                }
            }
        }
        StringBuilder ans = new StringBuilder();
        int x = n;
        int y = m;
        int len = dp[n][m];
        // 回去
        while (len > 0) {
            if (pos[x][y] == 0) {
                ans.insert(0, ch1[x]);
                len--;
                if (len == 0) {
                    break;
                }
            }
            // 细节
            int position = pos[x][y];
            x = x + posX[position];
            y = y + posY[position];
        }
        out.println(ans);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
